<!--资产添加-->
<template>
  <div style="margin-top: 60px;margin-left:330px;width: 300px;height: 500px;border: 0px solid red;" >
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
      <el-form-item label="扫描任务名称" prop="scanName">
        <el-input v-model="ruleForm.scanName"></el-input>
      </el-form-item>
      <el-form-item label="关联任务" prop="mytaskId">
        <el-select v-model="ruleForm.mytaskId" placeholder="请选择所关联的任务">
          <el-option v-for="item in TestList" :label="item.taskName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="参与的测试人员" prop="tester">
        <el-select v-model="ruleForm.tester" placeholder="请选择测试人员">
          <el-option v-for="item in tbIfAdminList" :label="item.username" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="发现的漏洞" prop="foundVul">
        <el-input v-model="ruleForm.foundVul"></el-input>
      </el-form-item>
      <el-form-item label="漏洞严重性" prop="riskLevel">
        <el-select v-model="ruleForm.riskLevel" placeholder="请选择漏洞严重性">
          <el-option label="低" value="低"></el-option>
          <el-option label="中" value="中"></el-option>
          <el-option label="高" value="高"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>
<script>
export default {
  data() {
    return {
      category:null,
      ruleForm: {
        scanName: '',
        tester: '',
        mytaskId: '',
        foundVul:'',
        riskLevel:'',
      },
      tbIfAdminList: '',
      TestList: '',
      rules: {
        scanName: [
          { required: true, message: '请输入扫描任务名称', trigger: 'blur' }
        ],

      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {

          axios.post('http://localhost:8181/tbTaskScan/save',_this.ruleForm).then(function (resp) {
            if(resp.data.code == 0){
              _this.$alert(_this.ruleForm.scanName+'添加成功', '', {
                confirmButtonText: '确定',
                callback: action => {
                  // _this.$router.push('/ScanAdd3')
                }
              });
            }
          })
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {
    const _this = this;

    // 获取所属任务数据
    axios.get('http://localhost:8181/tbTaskAttack/list').then(function (resp) {
      console.log(resp.data);  // 确保控制台中打印了正确的数据
      _this.TestList = resp.data.data;
    });
    // 获取资产负责人数据
    // axios.get('http://localhost:8181/tbTaskAttack/list').then(function (resp) {
    //   _this.TestList = resp.data.data;
    // });
    // 获取资产负责人数据
    axios.get('http://localhost:8181/tbIfadmin/list').then(function (resp) {
      _this.tbIfAdminList = resp.data.data;
    });
  }

}
</script>